🪲 [Fix]: Connect-GitHubApp no longer fails when only one installation exists#568
Conversation
a0225f5
into
main
There was a problem hiding this comment.
Pull request overview
Fixes Connect-GitHubApp so it can connect to all GitHub App installations reliably when the app has exactly one installation, avoiding a runtime failure caused by passing a single object (instead of an ICollection) into ArrayList.AddRange().
Changes:
- Wraps
Get-GitHubAppInstallationwith@()in the “connect to all installations” path to guarantee an array is passed toAddRange().
| default { | ||
| Write-Verbose 'No target specified. Connecting to all installations.' | ||
| $selectedInstallations.AddRange((Get-GitHubAppInstallation -Context $Context)) | ||
| $selectedInstallations.AddRange(@(Get-GitHubAppInstallation -Context $Context)) |
There was a problem hiding this comment.
Regression coverage: this change fixes the single-installation case, but the current Pester suite appears to only exercise the default (no-parameter) path against whatever installations exist in the test environment, and doesn’t assert behavior when Get-GitHubAppInstallation yields exactly one object (the scenario that previously threw). Add a targeted test that forces a single-installation return (e.g., via a controlled fixture/mocking or a dedicated test app with exactly one installation) and asserts Connect-GitHubApp -PassThru does not throw and returns one context.
Connect-GitHubAppnow correctly connects to all available installations regardless of whether one or many exist. Previously, callingConnect-GitHubAppwhen the GitHub App had exactly one installation caused anAddRangefailure, because PowerShell returned a single object instead of an array.Fixed: Connecting with a single app installation
Connect-GitHubApp(with no filter parameters) no longer throws when your GitHub App has only one installation. The command now handles one, many, or zero installations identically.This resolves the error:
Automation workflows (e.g., Distributor sync) that call
Connect-GitHubAppwithout parameters will no longer fail on single-installation apps.Technical Details
src/functions/public/Auth/Connect-GitHubApp.ps1ArrayList.AddRange()requires anICollection. WhenGet-GitHubAppInstallationreturns a single object, PowerShell does not wrap it in an array — the bare object doesn't implementICollection, causing the call to throw.@()to guarantee an array is always passed:$selectedInstallations.AddRange(@(Get-GitHubAppInstallation -Context $Context))